<?php

session_start();

require_once('../model/login.php');
include('../config/config.php');

$nip = $_POST['NIP'];
$pass = $_POST['pass'];

$login_model = new Login_model();
$res = $login_model->check_nip($nip, $pass);

if(mysql_num_rows($res) == 0){	
	$_SESSION['err'] = '<script type = "text/javascript">alert("NIP atau Password Salah")</script>';
	header('Location: ../login.php');
} else {
	$_SESSION['logged_in'] = true;
	while($row = mysql_fetch_array($res)){
		$nip = $row['NIP'];
		$id_role = $row['ID_ROLE'];
		$id_dep = $row['ID_DEPARTEMEN'];
		$id_tim = $row['ID_TEAM'];
		$_SESSION['NIP'] = $nip;
		$_SESSION['ID_ROLE'] = $id_role;
		$_SESSION['ID_DEPARTEMEN'] = $id_dep;
		$_SESSION['ID_TEAM'] = $id_tim;
		$role = $row['KETERANGAN'];
		
	if($_SESSION['ID_ROLE'] == 1){
		header ('location: ../gh/sdm/view/index.php');
	} else if($_SESSION['ID_ROLE'] == 2){
		header ('location: ../dh/sdm/view/index.php');	
	} else{
		header ('location: ../index.php');
	}		
	}
	
	
	
	
}

?>